compareFuncsCb
With this method, you can compare the execution time of several functions and get complete information from it
Params
compareFuncsCb(cb,runtimeCount = 5, ...inputFunctions)) ;
- runtimeCount → The number of times you want input functions to be executed and its time taken
- inputFunctions → The functions we want to compare their execution time with each other and compare
- Cb → A function that will be called as a callback and the output will be passed to this function
When you use this method, be sure to define the callback function
Returns
{
firstRuntimes: {
fastest: [ [Function: inpFunc3], 0.00604 ],
slowest: [ [Function: inpFunc1], 0.07471 ],
rank: [ [Array], [Array], [Array] ]
},
multiRuntimes: {
fastestRun: [ [Function: inpFunc1], 0.00033 ],
slowestRun: [ [Function: inpFunc2], 0.00204 ],
fastestAverage: [ [Function: inpFunc3], 0.00036 ],
slowestAverage: [ [Function: inpFunc2], 0.00085 ],
result: [ [Array], [Array], [Array] ]
}
}
-
Object.firstRuntimes → Comparison of functions in the first run
-
Object.firstRuntimes.fastest → Fastest execution time among functions
-
Object.firstRuntimes.slowest → Slowest execution time among functions
-
Object.firstRuntimes.rank → Execution time of all functions in the order of fastest to slowest
-
Object.multiRuntimes → Comparison of functions in the next several times of execution (by the number of runtimeCount)
-
Object.multiRuntimes.fastestRun → Fastest execution time among functions
-
Object.multiRuntimes.slowestRun → Slowest execution time among functions
-
Object.multiRuntimes.fastestAverage → Fastest execution time among functions
-
Object.multiRuntimes.slowestAverage → Slowest execution time among functions
-
Object.multiRuntimes.result → Execution times of each function(like getMultiRuntimeCb())
Usage
const inpFuncSync1 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
});
};
const inpFuncSync2 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 500);
});
};
const inpFuncSync3 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 3000);
});
};
compareFuncsCb((err,res)=>{
console.log(res);
/*
res = {
firstRuntimes: {
fastest: [ [AsyncFunction: inpFuncSync2], 501.90492 ],
slowest: [ [AsyncFunction: inpFuncSync3], 3001.49104 ],
rank: [ [Array], [Array], [Array] ]
},
multiRuntimes: {
fastestRun: [ [AsyncFunction: inpFuncSync2], 500.9653329999992 ],
slowestRun: [ [AsyncFunction: inpFuncSync3], 3000.7440420000003 ],
fastestAverage: [ [AsyncFunction: inpFuncSync2], 500.97432 ],
slowestAverage: [ [AsyncFunction: inpFuncSync3], 3000.72284 ],
result: [ [Array], [Array], [Array] ]
}
}
*/
},5,inpFuncSync1,inpFuncSync2,inpFuncSync3)